using GameFramework.Battle.Core;
using Gameplay.PVE.Config;
using Gameplay.PVE.Entity;
using Gameplay.PVE.Utils;
using UnityEngine;

namespace Gameplay.PVE.Skill
{
    //满足条件后触发技能
    public class SkillPassive : SkillBase
    {
        protected override void Storage()
        {
            CastEvent();
        }

        protected override void Cast()
        {
            BattleLog.UnitLog(unit,"触发被动"+config.id);
        }
        
        protected override void Recover()
        {
            
        }

        protected override void CastEvent()
        {
            if (config.summon_id != 0) //召唤类技能
            {
                UpdateSummonSkill();
            }
            else
            {
                base.CastEvent();
            }
        }

        protected override bool CheckIsCanSkill()
        {
            return true;
        }
        
        protected override void UpdateEffect(PveSkillConfig config)
        {
            var effectStateList = this.effectStateList[config.id];
            for (int i = 0; i < config.effects.Count; i++)
            {
                if (!effectStateList[i] && currentTime - effectStartTime >= config.effects[i].x / 30f)
                {
                    Vector3 position = unit.Data.position;
                    Vector3 forward = unit.Data.forward;
                    Transform parent = null;
                    if (unit.Data.skillEffectPoints.Count > config.effects[i].z)
                    {
                        position = unit.Data.skillEffectPoints[(int)config.effects[i].z].position;
                        var effectConfig = PveUtils.GetRpgEffectConfig((int) config.effects[i].y);
                        if (effectConfig.use_parent_forward == 1)
                        {
                            forward = unit.Data.skillEffectPoints[(int) config.effects[i].z].forward;
                        }

                        if (effectConfig.set_parent == 1)
                        {
                            parent = unit.Data.skillEffectPoints[(int) config.effects[i].z];
                        }
                        //parent = unit.Data.skillEffectPoints[(int) config.effects[i].z];
                        //forward = unit.Data.skillEffectPoints[(int)config.effects[i].z].forward;
                    }
                    PveEffectManager.Instance.PlayEffect((int)config.effects[i].y,position,forward,5,1,parent);
                    effectStateList[i] = true;
                }
            }
        }
    }
}